package com.example.demo.config.Persistence.persist;

import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
import org.springframework.stereotype.Component;

import com.example.demo.app.entity.FormEntity;
import com.example.demo.config.builder.ComplexFormStateMachineBuilder;
import com.example.demo.config.enum_.ComplexFormEvents;
import com.example.demo.config.enum_.ComplexFormStates;

@Component
public class ComplexFormStateMachinePersist implements StateMachinePersist<ComplexFormStates, ComplexFormEvents, FormEntity> {

	@Override
	public void write(StateMachineContext<ComplexFormStates, ComplexFormEvents> context, FormEntity contextObj) throws Exception {
		//这里不做任何持久化工作
	}

	@Override
	public StateMachineContext<ComplexFormStates, ComplexFormEvents> read(FormEntity contextObj) throws Exception {
		StateMachineContext<ComplexFormStates, ComplexFormEvents> result = new DefaultStateMachineContext<ComplexFormStates, ComplexFormEvents>(
				ComplexFormStates.valueOf(contextObj.getStatus()),
				null, null, null, null, "complexFormMachine");
		return result;
	}

}
